﻿/* Copyright © Hauer Engineering 2012 */

(function ($)
{
    $.setupNamespace('heng.ko');

    $.heng.ko.makeObservable = function (obj)
    {
        if (!obj)
            return null;

        var objObservable = {};

        if (obj instanceof Array)
        {
            objObservable = ko.observableArray(obj);
            return objObservable;
        }

        for (var prop in obj)
        {
            if (obj[prop] instanceof Array)
            {
                objObservable[prop] = ko.observableArray(obj[prop]);
            }
            else
            {
                if (typeof(obj[prop]) == 'object')
                {
                    objObservable[prop] = $.heng.ko.makeObservable(obj[prop]);
                }
                else
                {
                    objObservable[prop] = ko.observable(obj[prop]);
                }
            }
        }

        return objObservable;
    };
})(jQuery);